<script setup lang="ts">
import { RouterLink, RouterView } from 'vue-router'
import { useRoute,useRouter } from 'vue-router';
import {ref,reactive,onMounted} from 'vue'
import axios from 'axios'

const route=useRoute();
const router=useRouter();
const userName=localStorage.getItem("userName");

const menuUrl=ref([])
const getMenuUrl=()=>{
  axios.get("/api/Menu/GetMenuUserUrl")
  .then(res=>{
    menuUrl.value=res.data.data
    // console.log(menuUrl.value)
  })
  .catch(err=>{
    console.log(err);
  })
}

//跳转页面
const jump=(name:string)=>{
    router.push(name)
}

//退出登录
const quit = () => {
  localStorage.removeItem("userName");
  localStorage.removeItem("token");
  router.push('/');
}
onMounted(()=>{
  getMenuUrl();
})
</script>

<template>

  <div class="common-layout" style="height: 100%;">
    <el-container style="height: 100%;">
      <el-header
        style="background-color: #545c64;text-align: center;font-size: 35px;color: white;font-weight: bolder;">欢迎您 <span style="color: red;">【{{userName }}】</span></el-header>
      <el-container>
        <el-aside width="200px" style="background-color: #545c64;">

          <el-menu active-text-color="#ffd04b" background-color="#545c64" class="el-menu-vertical-demo"
            default-active="2" text-color="#fff" style="height: 100%;">
            <el-sub-menu :index="1">
              <template #title>
                <span>系统管理</span>
              </template>
                <el-menu-item v-for="item1 in menuUrl" @click="jump(item1.menuUrl)" :index="item1.menuUrl">{{item1.menuName}}</el-menu-item>
            </el-sub-menu>
            <el-sub-menu :index="2">
              <template #title>
                <span>请假管理</span>
              </template>
                <el-menu-item @click="jump('/Leaves/LeaveAdd')" index="2-1">请假申请</el-menu-item>
                <el-menu-item @click="jump('/Leaves/LeaveList')" index="2-2">请假管理</el-menu-item>
            </el-sub-menu>
            <el-sub-menu :index="3">
              <template #title>
                <span>溯源管理</span>
              </template>
                <el-menu-item @click="jump('/Traceabilities/TraceabilityList')" index="3-1">溯源列表</el-menu-item>
            </el-sub-menu>
                <el-menu-item @click="quit()">退出登录</el-menu-item>
          </el-menu>

        </el-aside>
        <el-main>
          <RouterView />
        </el-main>
      </el-container>
    </el-container>
  </div>

</template>

<!-- <style scoped>
header {
  line-height: 1.5;
  max-height: 100vh;
}

.logo {
  display: block;
  margin: 0 auto 2rem;
}

nav {
  width: 100%;
  font-size: 12px;
  text-align: center;
  margin-top: 2rem;
}

nav a.router-link-exact-active {
  color: var(--color-text);
}

nav a.router-link-exact-active:hover {
  background-color: transparent;
}

nav a {
  display: inline-block;
  padding: 0 1rem;
  border-left: 1px solid var(--color-border);
}

nav a:first-of-type {
  border: 0;
}

@media (min-width: 1024px) {
  header {
    display: flex;
    place-items: center;
    padding-right: calc(var(--section-gap) / 2);
  }

  .logo {
    margin: 0 2rem 0 0;
  }

  header .wrapper {
    display: flex;
    place-items: flex-start;
    flex-wrap: wrap;
  }

  nav {
    text-align: left;
    margin-left: -1rem;
    font-size: 1rem;

    padding: 1rem 0;
    margin-top: 1rem;
  }
}
</style> -->
